package zzs.generalframework.util.core.reflect;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;

import net.sf.cglib.core.Converter;
import zzs.generalframework.util.core.calendar.CalendarUtils;

/**
 * @title
 * @description
 * @project zzs-util
 * @package zzs.generalframework.util.core.reflect
 * @author zzs
 * @date 2018年1月30日
 * @version 1.0
 */
public class FieldTypeConverter implements Converter
{
	// @Override
	public Object convert(Object value, Class target, Object context)
	{
		Object returnObj = null;
		if (target.isAssignableFrom(Date.class))
		{
			try
			{
				returnObj = CalendarUtils.convertString2Date(value.toString());
			}
			catch (ParseException e)
			{
				returnObj = null;
			}
		}
		else if (target.isAssignableFrom(BigDecimal.class))
		{
			returnObj = new BigDecimal(value.toString());
		}
		else if (target.isAssignableFrom(String.class))
		{
			returnObj = value;
		}
		else
		{
			returnObj = value;
		}

		return returnObj;
	}

}
